package dcutils.rpg.currency;

// Import DCUtils Classes
import dcutils.tuples.Pair;

/**
 * A Quantity represents a number (quantity) of Units.<br/>
 * I.e.: 50 Gold, or 25 Silver, etc.<br/>
 * @see Unit
 * @author dca
 */
public class Quantity extends Pair<Unit, Integer> {
   public Quantity(Unit unit, Integer amt) {
      super(unit, amt);
   } // END constructor

   public Unit getUnit() {
      return first();
   } // END getUnit

   public Integer getAmount() {
      return second();
   } // END getAmount

   public int getBaseValue() {
      return getUnit().getBaseValue() * getAmount();
   } // END getBaseValue

   public static Quantity getQuantity(Unit unit, Integer amt) {
      return new Quantity(unit, amt);
   } // END getQuantity

   @Override
   public String toString() {
      return String.format("%s (%d)", getUnit().getBaseName(), getAmount());
   } // END toString

   @Override
   public boolean equals(Object obj) {
      if(null == obj) {
         return false;
      } else if(obj instanceof Quantity) {
    	  Quantity quantity = (Quantity)obj;

         return this.first().equals(quantity.first()) &&
        		this.second() == quantity.second();
      } else {
         return false;
      } // END if/else
   } // END equals

   @Override
   public int hashCode() {
      int hashCode = 101;
      hashCode = (11 * hashCode) + super.hashCode();
      return hashCode;
   } // END hashCode
} // END class Quantity
